﻿using System;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed;

namespace GMS.Utils
{
    public class RedisUtil
    {
        private readonly IDistributedCache _cache;  

        public readonly DistributedCacheEntryOptions DistributedCacheEntryOptions = new DistributedCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromHours(2));

        public RedisUtil(IDistributedCache cache)
        {
            _cache = cache;
        }

        public void SetAsync(string key, string value)
        {
            _cache.SetStringAsync(key, value);
        }

        public Task<string> GetStringAsync(string key)
        {
            return _cache.GetStringAsync(key);
        }

        public Task<byte[]> GetBufferAsync(string key)
        {
            return _cache.GetAsync(key);
        }

        public void SetAsync(string key, string value, DistributedCacheEntryOptions options)
        {
            _cache.SetStringAsync(key, value, options);
        }

        public void SetAsync(string key, byte[] value)
        {
            _cache.SetAsync(key, value);
        }

        public void SetAsync(string key, byte[] value, DistributedCacheEntryOptions options)
        {
            _cache.SetAsync(key, value, options);
        }



    }
}